import axios from 'axios'

axios.defaults.timeout = 5000
// axios.defaults.baseURL = 'http://gq.youledi.cn'
// axios.defaults.baseURL = '/api'
axios.defaults.headers.post['Content-Type'] = 'application/json'
// axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded'
// axios.defaults.headers['Content-Type'] = 'application/x-www-form-urlencoded'
// axios.defaults.headers.post['xhrFields'] = {'withCredentials': true}
// axios.defaults.headers.get['xhrFields'] = {'withCredentials': true}
// axios.defaults.headers.post['crossDomain'] = true
// axios.defaults.headers.get['crossDomain'] = true
axios.defaults.transformRequest = [function (data) {
  let ret = ''
  for (let it in data) {
    ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
  }
  ret = ret.substring(0, ret.length - 1)
  return ret
}]

export default axios
